package com.springboot.love.controller;

import com.alibaba.fastjson.JSONObject;
import com.springboot.love.dao.SetDao;
import com.springboot.love.entity.SetLove;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class SetController {

    @Resource
    private SetDao setDao;


    @RequestMapping("/admin/setList")
    public String setList(Model model){
        List<SetLove> sets = setDao.selectList(null);
        model.addAttribute("set",sets);
        return "admin/set";
    }

    @RequestMapping("/admin/setupdate")
    @ResponseBody
    String setupdate(String settitle,String setqq,String setimage,String setemail,
                     String setkeywords,String setdescript,String setwait,String settongji,String setbanquan){
        SetLove setLove = new SetLove();
        setLove.setSetId(1);
        setLove.setSetTitle(settitle);
        setLove.setSetQq(setqq);
        setLove.setSetEmail(setemail);
        setLove.setSetImage(setimage);
        setLove.setSetTongji(settongji);
        setLove.setSetBanquan(setbanquan);
        setLove.setSetKeywords(setkeywords);
        setLove.setSetDescription(setdescript);
        setLove.setSetWait(setwait);
        JSONObject jsonObject = new JSONObject();
        if (setDao.updateById(setLove)>0){
            jsonObject.put("success",true);
        }else {
            jsonObject.put("success",false);
        }
        return jsonObject.toString();
    }
}
